
$(document).ready(function () {
    queryDeviceData()

    $('.log-check>div').eq(0).click()

})



// 状态统计
queryDeviceData = () => {
    AjaxRequest('/valve/device/status/count', callBack)

    function callBack(result) {
        if (result.status == 200) {
            var data = result.result;

            $('.realtime-item').eq(0).find('.realtime-data').html(data.oil)
            $('.realtime-item').eq(1).find('.realtime-data').html(data.valve)
            $('.realtime-item').eq(2).find('.realtime-data').html(data.stop)
            $('.realtime-item').eq(3).find('.realtime-data').html(data.start)
            $('.realtime-item').eq(4).find('.realtime-data').html(data.auto)
            $('.realtime-item').eq(5).find('.realtime-data').html(data.manual)

        }
    }
}

$('.log-check>div').click(function (e) {
    $(e.currentTarget).addClass('active').siblings().removeClass('active');

    queryAlarmList($(e.currentTarget).data().type)

})



// 告警列表 

queryAlarmList = (type) => {

    switch (type) {
        case 1:
            var url = '/valve/data/ss/list?pageNum=1&pageSize=5'
            break;
        case 2:
            var url = '/valve/data/ma/list?pageNum=1&pageSize=5'
            break;

        default:
            break;
    }

    AjaxRequest(url, callBack)

    function callBack(result) {
        if (result.status == 200) {
            var list = result.result.data;

            if (list.length == 0) {
                $('.alarm-list').empty().append('<div style="width: 100%;height: 2.5rem;display: flex;align-items: center;justify-content: center;"><img src="../static/img/nodata.png"></div>')
            } else {
                $('.alarm-list').empty().append(list.reduce((x, y) => {
                    return x + `<div class="alarm-list-item">
                                <div>${y.name}</div>
                                <div>${y.valueDesc}</div>
                                <div>${y.dataTime}</div>
                            </div>`
                }, ` <div class="alarm-list-item"><div>阀门名称</div><div>阀门状态</div><div>上报时间</div></div>`))
            }



        }
    }
}

$('.data-more').click(function () {
    window.open('../html/realtimedata.html');
})

$('.alarm-more').click(function () {
    window.open('../html/logmanagement.html');
})
